<?php
/**
 * Created by PhpStorm.
 * User: l
 * Date: 2018/10/22
 * Time: 17:58
 */
namespace app\models;
use yii\db\ActiveRecord;

class Gl_banner extends ActiveRecord{
	public function getBannerList($limit, $offset){
		$post = Gl_banner::find();

		$count = $post->count();
		$result = $post->limit($limit)->offset($offset)->asArray()->all();

        return ['total'=>$count, 'rows'=>$result];
	}

	//更新广告资料
    public function updateBanner($bannerId, $isDeleted, $bannerType, $bannerPic, $bannerUrl, $weightValue) {
        $banner = Gl_banner::findOne(['banner_id' => $bannerId]);

        if ($isDeleted != -1) {
            $banner->is_deleted = $isDeleted;
        }
        if ($bannerType != -1) {
        	$banner->banner_type = $bannerType;
        }
        if ($bannerPic != -1) {
        	$banner->banner_pic = $bannerPic;
        }
        if ($bannerUrl != -1) {
        	$banner->banner_url = $bannerUrl;
        }
        if ($weightValue != -1) {
        	$banner->weight_value = $weightValue;
        }

        $result = $banner->save();
        return $result;
    }

    public function editBanner($banner_id) {
        $result = Gl_banner::find()->where(['banner_id' => $banner_id])->asArray()->one();

        return $result;
    }

    // 查询所有广告图数据
    public function showBanner(){
    	$result = Gl_banner::find()->asArray()->all();
    	return $result;
    }
}